package pfc.pfcjoc.entities;

// import static playn.core.PlayN.log;

import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.Fixture;
import org.jbox2d.dynamics.FixtureDef;
import org.jbox2d.dynamics.World;

import pfc.pfcjoc.core.pfcjoc;
import playn.core.GroupLayer;

public class EndBlock extends PhysicElement {
  public static String name = "endblock";


  public EndBlock(final World world, final GroupLayer worldLayer, final Vec2 pos) {
    super(world, worldLayer, pos);
    setDepth(10);
    initPhysics(world, pos);
  }


  public void initPhysics(World world, Vec2 pos) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.STATIC;
    bodyDef.position = pos;
    body = world.createBody(bodyDef);

    PolygonShape polygon = new PolygonShape();
    float w = pfcjoc.toPhy(getWidth());
    float h = pfcjoc.toPhy(getHeight());
    polygon.setAsBox(w / 2f, h / 2f);

    FixtureDef fxtDefEndBlock = new FixtureDef();
    fxtDefEndBlock.isSensor = true;
    fxtDefEndBlock.shape = polygon;
    fxtDefEndBlock.friction = 0.0f;

    Fixture endBlockFxt = body.createFixture(fxtDefEndBlock);
    endBlockFxt.setUserData("endBlock");

    setPosPhy(pos); // BLOCK
    // setPosPhy(pfcjoc.toPhy(pos)); BUSH

    // Útil per gestió de colisions
    body.setUserData(this);
  }


  // public void paint(float alpha) {
  // super.paint(alpha);
  // // sprite.setSprite(spriteIndex);
  // }

  public String getName() {
    return name;
  }


  @Override
  public float getWidth() {
    return 64;
  }


  @Override
  public float getHeight() {
    return 96;
  }


  @Override
  protected int getFirstSprite() {
    return 0;
  }


  @Override
  protected String getImagePath() {
    return "images/endblock.png";
  }


  @Override
  protected String getJsonPath() {
    return "images/endblock.json";
  }
}
